package com.zxl.manager.service.impl;

import com.zxl.manager.dao.ApiDao;
import com.zxl.manager.dao.CommDao;
import com.zxl.manager.entity.WxRes;
import com.zxl.manager.service.ApiService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by 逍遥的熊 on 2017/8/14.
 */
@Service
public class ApiServiceImpl implements ApiService {

    @Autowired
    private ApiDao apiDao;

    @Autowired
    private CommDao commDao;

    public void AnsWxEvent(WxRes wxRes,String sourceStr){
        switch (wxRes.getEvent()){
            case "subscribe":
                wxSubscr(wxRes,sourceStr);
                break;
            default:
                apiDao.insWxEvent(wxRes,sourceStr);
                break;
        }
    }

    private void wxSubscr(WxRes wxRes,String sourceStr){
        if(StringUtils.isNotEmpty(wxRes.getEventKey())){
            commDao.insCommRel(wxRes.getEventKey().substring(8),wxRes.getFromUserName());
            apiDao.insWxEvent(wxRes,sourceStr);
        }
    }
}
